﻿using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml.Serialization;
using LoLTimers.Utilities;

namespace LoLTimers.DataObjects
{
    [Serializable]
    public class TimerDataObject
    {
        private GameDataObject _gdo;
        private string _id;
        private string _text;
        private SerializableFont _font;
        private Color _foreColor;
        private Color _alertColor;
        private int _alertSeconds;
        private int _urgentAlertSeconds;       
        private string _timerType;
        private Image _image;
        private string _imagePath;
        private Color _backgroundColor;
        private Point _location;
        private Size _size;
        //private Keys _modifierKey;
        private Keys _shortcutKey;
        
        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }
        
        [XmlIgnore] //Pair them manually on the timerType property and GameData ID
        public GameDataObject GameData
        {
            get { return _gdo; }
            set { _gdo = value; }
        }

        public string TimerType
        {
            get { return _timerType; }
            set { _timerType = value; }
        }
       
        public string Text
        {
            get { return _text; }
            set { _text = value; }
        }
        
        public SerializableFont TimerFont
        {
            get { return _font; }
            set { _font = value; }
        }

        [XmlIgnore]
        public Color ForeColor
        {
            get { return _foreColor; }
            set { _foreColor = value; }
        }

        public string XmlForeColor
        {
            get { return _foreColor.Name; }
            set { _foreColor = Color.FromName(value); }
        }

        [XmlIgnore]
        public Color AlertColor
        {
            get { return _alertColor; }
            set { _alertColor = value; }
        }

        public string XmlAlertColor
        {
            get { return _alertColor.Name; }
            set { _alertColor = Color.FromName(value); }
        }

        [XmlIgnore]
        public Color BackgroundColor
        {
            get { return _backgroundColor; }
            set { _backgroundColor = value; }
        }

        public string XmlBackgroundColor
        {
            get { return _backgroundColor.Name; }
            set { _backgroundColor = Color.FromName(value); }
        }

        public int AlertSeconds
        {
            get { return _alertSeconds; }
            set { _alertSeconds = value; }
        }

        public int UrgentAlertSeconds
        {
            get { return _urgentAlertSeconds; }
            set { _urgentAlertSeconds = value; }
        }

        [XmlIgnore]
        public Image DisplayImage
        {
            get
            {
                try
                {
                    if (_image == null)
                        _image = Image.FromFile(_imagePath);
                    return _image;
                }
                catch(Exception ex)
                {
                    return Properties.Resources.FileNotFoundImage;
                }
            }
            set { _image = value; }
        }

        public string DisplayImagePath
        {
            get { return _imagePath; }
            set { _imagePath = value; }
        }

        //public Keys ModifierKey
        //{
        //    get { return _modifierKey; }
        //    set { _modifierKey = value; }
        //}

        public Keys ShortcutKey
        {
            get { return _shortcutKey; }
            set { _shortcutKey = value; }
        }

        [XmlIgnore]
        public Rectangle Bounds
        {
            get { return new Rectangle(_location, _size); }
            set
            {   
                _location = value.Location;
                _size = value.Size;
            }
        }

        public Point Location
        {
            get { return _location; }
            set { _location = value; }
        }

        public Size Dimension
        {
            get { return _size; }
            set { _size = value; }
        }
    }
}
